package com.megvii.koala.tv.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.megvii.koala.tv.R;

/**
 * Created by linyue on 16/1/26.
 */
public class TVErrorView extends RelativeLayout
{
    private ImageView icon;

    private TextView title;

    private TextView info;

    public TVErrorView(Context context)
    {
        super(context);
        init(null);
    }

    public TVErrorView(Context context, AttributeSet attrs)
    {
        super(context, attrs);
        init(attrs);
    }

    public TVErrorView(Context context, AttributeSet attrs, int defStyle)
    {
        super(context, attrs, defStyle);
        init(attrs);
    }

    private void init(AttributeSet attrs)
    {
        inflate(getContext(), R.layout.tv_error_layout, this);
        icon = (ImageView) findViewById(R.id.tv_error_icon);
        title = (TextView) findViewById(R.id.tv_error_title);
        info = (TextView) findViewById(R.id.tv_error_description);
        if (attrs != null)
        {
            TypedArray array = getContext().obtainStyledAttributes(attrs, R.styleable.TVError);
            int iconResId = array.getResourceId(R.styleable.TVError_icon, R.layout.tv_error_layout);
            String titleText = array.getString(R.styleable.TVError_titleText);
            String infoText = array.getString(R.styleable.TVError_infoText);
            setIconImage(iconResId);
            setTitleText(titleText);
            setInfotext(infoText);
        }
    }

    public void setIconImage(int resId)
    {
        icon.setImageResource(resId);
    }

    public void setTitleText(String titleText)
    {
        title.setText(titleText);
    }

    public void setInfotext(String infoText)
    {
        info.setText(infoText);
    }
}
